from django import http
from django.shortcuts import render

# Create your views here.
from django.views import View

from apps.mqtt.models import DHT11, HX711
from utils.response_code import RETCODE


class Test(View):
    def get(self, request):
        return http.JsonResponse({'code': 'ok'})


class DHT11View(View):
    def get(self, request):
        hum = request.GET.get('hum')
        tem = request.GET.get('tem')
        DHT11.objects.create(tem=tem, hum=hum)
        return http.JsonResponse({'code': RETCODE.OK, 'errmsg': '温湿度上报成功'})


class HX711View(View):
    def get(self, request):
        weight = request.GET.get('weight')
        HX711.objects.create(weight=weight)
        return http.JsonResponse({'code': RETCODE.OK, 'errmsg':'重量上报成功'})